<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="JS/jquery-2.1.1.min.js"></script>
</head>
<body>
	<input name="file" type="file" id="file" />
	<button value="上传" onclick="upload()" >上传</button>
</body>
<script type="text/javascript">
	function upload(){
		
		var fd = document.getElementById("file");
		
		postfile(fd.files[0]);
	}
	function postfile(file){
		var http_request = false;
		if(window.XMLHttpRequest){
			http_request = new XMLHttpRequest();
		}else if(window.ActiveXObiect){
			try {
				http_request = new ActiveXObject("Msxml2.XMLHTTP")
			} catch (e) {
				try {
					http_request = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
		}
		
		http_request.open("POST","UpLoadServlet",true);
		http_request.setRequestHeader("Content-Type", "multipart/form-data");
		http_request.onreadystatechange = function () {
			if(http_request.readyState==4&&http_request.status==200){
				alert("图片上传成功");
			}else if(http_request.readyState!=4){
				alert("图片上传失败");
			}else{
				alert("涂片");
			}
		}
		http_request.send(file);
	}
</script>
</html>